<template>
    <view class="content">
        <view class="top">
            <view class="padding-lr-sm">
                <u-search placeholder="搜索内容" v-model="keyword" :show-action="false" height="70" @search="doSearch"></u-search>
            </view>
            <timeSearch @doSearch="doSearch" />
            
            <view class="nav">
                <view class="nav-i" :class="{active : type == 1}" @click="chooseNav(1)">待验货</view>
                <view class="nav-i" :class="{active : type == 2}" @click="chooseNav(2)">已验货</view>
				<view class="nav-i" :class="{active : type == 3}" @click="chooseNav(3)">拒收</view>
            </view>
        </view>
        
        <view class="box text-df" v-for="(item, index) in list" :key="index" @click="toDetails(item)">
            <view class="item">
                <view class="item-l">{{ number == 2 ? '单号' : '采购单号' }}</view>
                <view class="item-r">{{item.belong}}</view>
            </view>
            <view class="item">
                <view class="item-l">供货企业</view>
                <view class="item-r">{{item.company}}</view>
            </view>
            <view class="item">
                <view class="item-l">供货企业销售人员</view>
                <view class="item-r">{{item.account}}</view>
            </view>
			
			<view class="item" v-if="type == 3">
			    <view class="item-l">审核状态</view>
			    <view class="item-r">{{ item.status_txt }}</view>
			</view>
			<view class="item" v-if="type == 3 && item.reason">
			    <view class="item-l">拒绝原因</view>
			    <view class="item-r">{{ item.reason }}</view>
			</view>
        </view>
        
        <view style="height: 94rpx;padding-top: 30rpx;">
            <u-loadmore :status="status" v-if="status != 'loadmore'" />
        </view>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                status: 'loadmore', //是否显示没有更多了
                page: 1,
                list: [],
                type: 1,
                keyword: '',
                startTime: '',
                endTime: '',
                number: 1,//2 二次验收
            };
        },
        onLoad(option) {
            if (option.number) {
                this.number = option.number
                uni.setNavigationBarTitle({
                	title:'二次验收'
                })
            }
        },
        onShow() {
            this.list = []
            this.page = 1
            this.status = 'loadmore'
            this.getList()
        },
        onReachBottom() {
        	if(this.page == 1){return}
        	this.getList()
        },
        methods: {
            toDetails(item) {
                // order_status = 0未收货 1-已收货,待验收  2-已验收,待二次验收  3-已二次验收  4-已入库
                if (this.type == 1) {
                    this.$gTo(`/pages/enter-buy/take-check-details?id=${item.id}&type=${1}&order_status=${item.order_status}`)
                } else {
                    // this.$gTo(`/pages/enter-record/enter-details?id=${item.id}&type=${2}&order_status=${item.order_status}`)
					this.$gTo(`/pages/enter-record/enter-details?id=${item.id}&type=${this.type}&order_status=${item.order_status}`)
                }
            },
            
            doSearch(data) {
                if (data) {
                    this.startTime = data.startTime
                    this.endTime = data.endTime
                }
                this.page = 1;
                this.list = [];
                this.status = 'loadmore';
                this.getList()
            },
            
            chooseNav(num) {
                if (this.type == num) return
                this.type = num
                this.list = []
                this.page = 1
                this.status = 'loadmore'
                this.getList()
            },
            
            getList() {
                let url = '', promise = {}
				if (this.type == 3) {
					// 拒收
					url = 'inventory_put/check_refuse'
					promise = {
					    userToken: this.$getSync('userToken'),
					    page: this.page,
					    limit: 10,
					    keywords: this.keyword,
					    start_time: this.startTime,
					    end_time: this.endTime,
					}
				} else if (this.type == 1) {
					if (this.number == 1) {
						// 待验收
						url = 'inventory_put/take_list'
						promise = {
						    userToken: this.$getSync('userToken'),
						    page: this.page,
						    limit: 10,
						    type: 1, //类型 1-采购 2-销售退货
						    keywords: this.keyword,
						    start_time: this.startTime,
						    end_time: this.endTime,
						}
					}
					if (this.number == 2) {
						// 待二次验收
						url = 'inventory_put/second_list'
						promise = {
						    userToken: this.$getSync('userToken'),
						    page: this.page,
						    limit: 10,
						    keywords: this.keyword,
						    start_time: this.startTime,
						    end_time: this.endTime,
						}
					}
                } else {
                    // 已验收
                    url = 'inventory_put/check_list'
                    promise = {
                        userToken: this.$getSync('userToken'),
                        page: this.page,
                        limit: 10,
                        keywords: this.keyword,
                        start_time: this.startTime,
                        end_time: this.endTime,
                    }
                }
                
            	if (this.status == 'nomore') return;
            	this.status = 'loading';
            	this.$ajax(url, promise).then(ret => {
            		if (ret.status == 0) {
                        if (ret.data.length > 0) {
                        	this.list = this.list.concat(ret.data);
                        	this.page++;
                        	this.status = 'loadmore'
                        } else {
                        	this.status = 'nomore'
                        }
            		} else {
            			this.$toast(ret.message);
            		}
            	});
            },
        }
    };
</script>

<style lang="scss">
    
    page{
        background-color: #f5f5f5 !important;
    }
    .top{
        background-color: #fff;
    }
    .nav{
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    .nav-i{
        width: calc(100vw / 3);
        font-size: 30rpx;
        font-weight: bold;
        text-align: center;
        padding-bottom: 30rpx;
    }
    .active{
        color: #ff4800;
        position: relative;
    }
    .active::after{
        display: block;
        content: '';
        width: 32rpx;
        height: 8rpx;
        background-color: #ff4800;
        position: absolute;
        bottom: 0;
        left: 50%;
        transform: translateX(-50%);
    }
    
    
    .box{
        background-color: #fff;
        border-radius: 15rpx;
        padding: 30rpx;
        margin: 25rpx 25rpx 0;
    }
    .item{
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding-bottom: 15rpx;
    }
    .item:last-child{
        padding-bottom: 0;
    }
    .item-l{
        width: 245rpx;
        color: #868686;
    }
    .item-r{
        flex: 1;
        word-break: break-all;
        white-space: pre-line;
    }

</style>
